package com.xbongbong.saas.toolbox.help;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;

import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.saas.constant.StringConstant;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/5/1 9:48
 * @since v1.0
 */
public final class TimeUtil {
    private static Integer one_minute = 60;
    private static Integer one_hour = 60 * 60;
    private static Integer one_day = 60 * 60 * 24;

    public static String getString(Integer time){
        if (time < one_minute){
            return time + I18nMessageUtil.getMessage(CommonConstant.SECOND);
        }else if (time < one_hour){
            return time / one_minute + I18nMessageUtil.getMessage(CommonConstant.MINUTE);
        }else if (time < one_day){
            return time / one_hour + I18nMessageUtil.getMessage(CommonConstant.HOUR);
        }else {
            return time / one_day + I18nMessageUtil.getMessage(CommonConstant.DAY);
        }
    }
    public static String analysisLastConnectTime(Long time){
        if (Objects.isNull(time) || Objects.equals(time,0L)){
            return I18nMessageUtil.getMessage(StringConstant.NEVER_CONNECT);
        }
        Integer flag = DateTimeUtil.lastConnect(time,DateTimeUtil.getInt());
        if (flag <= 0) {
            return I18nMessageUtil.getMessage(I18nStringConstant.CONTACTED_TODAY);
        }else if(flag <= 30){
            return flag + I18nMessageUtil.getMessage(I18nStringConstant.DAYS_NOT_CONNECTED);
        }else if(flag <= 30*2) {
            return I18nMessageUtil.getMessage(I18nStringConstant.NOT_CONTACTED_MORE_ONE_MONTH);
        }else if(flag <= 30*3) {
            return I18nMessageUtil.getMessage(I18nStringConstant.NOT_CONTACTED_MORE_TWO_MONTH);
        }else {
            return I18nMessageUtil.getMessage(I18nStringConstant.NOT_CONTACTED_MORE_THREE_MONTH);
        }
    }
}
